function vec_length(c) {
    var len = c.x*c.x;
    len += c.y*c.y;
    len += c.z*c.z;
    return Math.sqrt(len);
};

function pts_distance(ca, cb) {
    var c = new coord(ca.x,ca.y,ca.z);
    c.x -= cb.x;
    c.y -= cb.y;
    c.z -= cb.z;
    return vec_length(c);
}

function vec_normalize(c) {
    var len = vec_length(c);
    return new coord(c.x/len, c.y/len, c.z/len);
};

function vec_dotp(ca, cb) {
    return ca.x*cb.x + ca.y*cb.y + ca.z*cb.z;
};

function vec_crossp(ca, cb) {
    return new coord(
	ca.y*cb.z-ca.z*cb.y,
	ca.z*cb.x-ca.x*cb.z,
	ca.x*cb.y-ca.y*cb.x );
};

function mat_product(ma, mb) {
    var mat = new matrix();
    for(var i = 0; i < 4; ++i) {
	for(var j = 0; j < 4; ++j) {
	    var sum = 0;
	    for(var k = 0; k < 4; ++k) {
		sum += ma[i][k]*mb[k][j];
	    }
	    mat[i][j] = sum;
	}
    }
    return mat;
};
